﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.Windows.Forms;

namespace CIRDiagnoseDevice.Test
{
    class InitSerialPort
    {
        SerialPort port;
        public SerialPort InitPort(string portName, int baudRate)
        {
            port = new SerialPort(portName, baudRate);
            port.DataBits = 8;
            port.StopBits = StopBits.One;
            port.ReadBufferSize = 4096;
            port.WriteBufferSize = 1024;
            return port;
        }

        public void Open( SerialPort osp)
        {
           
            if (!osp.IsOpen)
            {
                try
                {
                    osp.DataBits = 8;
                    osp.StopBits = StopBits.One;
                    osp.ReadBufferSize = 4096;
                    osp.WriteBufferSize = 1024;
                    osp.Open();
                }
                catch
                {
                    MessageBox.Show("串口" + osp.PortName + "打开失败！请查看串口是否被占用");
                }
            }
        }
    }
}
